import enterDepotDetailList from "../../api/aftersale-enter-depot-detail";
import dateOptions from "@/utils/date"; //引入date的渲染

let brand = {
    data(){
        return{
            dateOptions,
            tableData: [],//数据信息
            id: this.$route.query.id,//跨页面传参
            total: 0,//总条数
            searchParams: {
                currentPage: 1,
                pageSize: 5,
            },
            formData: {
            },//新增表单信息
            batchIds: [],//批量删除  判断选中是否修改 和删除
        }
    },
    methods:{
        /**
         * 查询所有
         */
        async searchPage() {
            console.log(this.searchParams);
            let response = await enterDepotDetailList.findPage(this.searchParams);
            this.total = response.total;//总行数赋值
            this.tableData = response.data;//数据信息赋值
        },
        //根据id查询
        async findById() {
            this.formData = await enterDepotDetailList.findById(this.id);

            if (this.formData.inType == 1) {
                this.formData.inType = "返厂维修入库";
            } else if (this.formData.inType == 2) {
                this.formData.inType = "退换货入库";
            }
            if (this.formData.inStatus == 0) {
                this.formData.inStatus = "待入库";
            } else if (this.formData.inStatus == 1) {
                this.formData.inStatus = "已入库";
            }
        },

        //checkbox勾选改变
        selectChange(val) {
            console.log(val)
            /**
             * 复选框选择修改 进行id赋值
             */
            if (val.length == 1) {
                //id赋值
                this.formData.id = val[0].id;
            } else {
                this.formData.id = "";
            }


            //勾选二个的时候修改失效  删除有效
            this.batchIds = val.map(item => item.id)
        },
        currentPageChange(currentPageIndex) {
            console.log(currentPageIndex);
            this.searchParams.currentPage = currentPageIndex;
            this.searchPage();
        },
    },
    created(){
        this.findById();
        this.searchPage();
    }
};

export default brand;